package Listener;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

@WebListener
public class OnLineListener implements HttpSessionListener {
    private int onlineCount = 100;

    public OnLineListener() {
    }

    @Override
    public void sessionCreated(HttpSessionEvent hse) {
        /* Session is created. */
        ServletContext context = hse.getSession().getServletContext();
        context.setAttribute("onlineCount", onlineCount);
        onlineCount++;
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent hse) {
        /* Session is destroyed. */
        onlineCount--;
        ServletContext context = hse.getSession().getServletContext();
        context.setAttribute("onlinrCount", onlineCount);
    }

}
